package job;

import java.util.Objects;

/**
 * 面试题总结
 * Author: hu
 * Date: 2022/3/1 11:16
 */
public class FaceTest {
    public static void main(String[] args) throws CloneNotSupportedException {
        student st1 = new student(12,"张三");
        student st2 = (student) st1.clone();
        st2.setAge(123);


        System.out.println("st1.equals(st2):"+st1.equals(st2));
        System.out.println(st1.hashCode()+":"+st2.hashCode());
        

    }
}

class student implements Cloneable{
    int age;
    String name;


    public student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        student student = (student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
